package edu.rmit.service.impl;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.List;

import edu.rmit.dao.IGroupDAO;
import edu.rmit.dao.impl.GroupDAOImpl;
import edu.rmit.domain.Group;
import edu.rmit.domain.User;
import edu.rmit.service.IGroupService;

@SuppressWarnings("serial")

/**
 * This class is to implement the group operation. Like get groups by
 * status, delete group, and change group status function.
 * 
 * @author Thaw Zin
 * @version 1.0
 */
public class GroupServiceImpl extends UnicastRemoteObject implements
		IGroupService {
	/**
	 * This instance can be manipulated to implement the database opertion.
	 */
	private IGroupDAO groupInfoDAO;

	/**
	 * The constructor to initialize a database operation instance.
	 * @throws RemoteException
	 */
	public GroupServiceImpl() throws RemoteException {
		groupInfoDAO = new GroupDAOImpl();
	}

	/**
	 * This method is to implement get groups by status.
	 * 
	 * @param destincationStatus
	 *            The destination status of the group
	 * @return A list of group which the group status is in this status
	 */
	@Override
	public List<Group> getInterestGroups(boolean isActive) throws RemoteException {
		return groupInfoDAO.getGroupsByStatus(isActive);
	}
	
	/**
	 * This method is to implement add a group to the system.
	 * 
	 * @param currentUser
	 *            The current user who want to add a group
	 * @param name
	 *            The group name which the user want to to add
	 * @param description
	 *            The description of the group.
	 */
	@Override
	public void addGroup(User currentUser, String name, String description) throws RemoteException {
		groupInfoDAO.addGroup(currentUser, name, description);
	}
	
	/**
	 * The method is to delete a group by id.
	 * 
	 * @param groupId
	 *            The group id which a user want to delete.
	 */
	@Override
	public void removeGroup(int groupId) throws RemoteException {
		groupInfoDAO.deleteGroup(groupId);		
	}
	
	/**
	 * This method is to implement change a group status.
	 * 
	 * @param groupId
	 *            The group id which a group want to change.
	 * @param destinationStatus
	 *            The destination status which a current group's status.
	 */
	@Override
	public void changeGroupStatus(int groupId, boolean destinationStatus)
			throws RemoteException {
		groupInfoDAO.changeGroupStatus(groupId, destinationStatus);
	}
}
